﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class art : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _id;
private System.String _name;
private System.DateTime? _date;
private System.String _description;
private System.String _path;
private System.String _text;
private System.Int32 _art_type_id;
private System.Int32 _user_id;
private System.Int32? _gallery_id;
private IList<art_rate_type> _art_rate_types;
private IList<art_tag> _art_tags;
private IList<comment> _comments;
private IList<lastWeekVisit> _lastWeekVisits;
private IList<topRated> _topRateds;
private IList<visit> _visits;
private art_type _art_type;
private gallery _gallery;
private user _user;

#endregion


#region --- Class Properties ---

public virtual System.Int32 id 
{
get
{
return _id;
}
}

public virtual System.String name 
{
get
{
return _name;
}
set 
{
if ( _name != value) 
{
_name = value ;
OnPropertyChanged("name");
}
}
}

/// <summary>
/// This property contains a calculated, bindable value of the DATE part of a DateTime property. If you want to only work with the DATE and ignore the underlying TIME component then you could use this property.
/// </summary>
/// <remarks>
/// Auto-Generated Property
/// </remarks>
public virtual System.String date_Date 
{
get
{
if (  !date.HasValue ) 
{ 
 return String.Empty;
} 
else 
{ 
if ( date.Value.ToShortDateString() == System.DateTime.MinValue.ToShortDateString() ) 
 return String.Empty;
else  
 return date.Value.ToShortDateString();
} 

}
set 
{
if ( string.IsNullOrEmpty( value ) )  
{
 if (string.IsNullOrEmpty(date_Time)) {

date = null;
}
 else
{
 date = Convert.ToDateTime( " " + System.DateTime.MinValue.ToShortDateString() + " " + date.Value.ToString("HH:mm:ss.fff") ) ;
}
}
 else
{
 if (string.IsNullOrEmpty(date_Time)) 
{
 date = Convert.ToDateTime( " " + value + " " + System.DateTime.MinValue.ToLongTimeString() ) ;
}
 else
{
 date = Convert.ToDateTime( " " + value + " " + date.Value.ToString("HH:mm:ss.fff") ) ;
}
}

}
}

/// <summary>
/// This property contains a calculated, bindable value of the TIME part of a DateTime property. If you want to only work with the TIME and ignore the underlying DATE component then you could use this property.
/// </summary>
/// <remarks>
/// Auto-Generated Property
/// </remarks>
public virtual System.String date_Time 
{
get
{
if (  !date.HasValue ) 
{ 
 return String.Empty;
} 
else 
{ 
if ( date.Value.ToShortTimeString() == System.DateTime.MinValue.ToShortTimeString() ) 
 return String.Empty;
else  
 return date.Value.ToShortTimeString();
} 

}
set 
{
if ( string.IsNullOrEmpty( value ) )  
{
 if (string.IsNullOrEmpty(date_Date)) 
{
date = null;
}
 else
{
 date = Convert.ToDateTime( " " + date.Value.ToShortDateString() + " " + System.DateTime.MinValue.ToLongTimeString() ) ;
}
}
 else
{
 if (string.IsNullOrEmpty(date_Date)) 
{
 date = Convert.ToDateTime( " " + System.DateTime.MinValue.ToShortDateString() + " " + value ) ;
}
 else
{
 date = Convert.ToDateTime( " " + date_Date + " " + value ) ;
}
}

}
}

public virtual System.DateTime? date 
{
get
{
return _date;
}
set 
{
if ( _date != value) 
{
_date = value ;
OnPropertyChanged("date");
}
}
}

public virtual System.String description 
{
get
{
return _description;
}
set 
{
if ( _description != value) 
{
_description = value ;
OnPropertyChanged("description");
}
}
}

public virtual System.String path 
{
get
{
return _path;
}
set 
{
if ( _path != value) 
{
_path = value ;
OnPropertyChanged("path");
}
}
}

public virtual System.String text 
{
get
{
return _text;
}
set 
{
if ( _text != value) 
{
_text = value ;
OnPropertyChanged("text");
}
}
}

public virtual System.Int32 art_type_id 
{
get
{
if ( art_type != null ) 
{
_art_type_id = (System.Int32)art_type.id;
}

return _art_type_id;
}
set 
{
if ( _art_type_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_art_type = null;

_art_type_id = value ;
OnPropertyChanged("art_type_id");
}
}
}

public virtual System.Int32 user_id 
{
get
{
if ( user != null ) 
{
_user_id = (System.Int32)user.id;
}

return _user_id;
}
set 
{
if ( _user_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_user = null;

_user_id = value ;
OnPropertyChanged("user_id");
}
}
}

public virtual System.Int32? gallery_id 
{
get
{
if ( gallery != null ) 
{
_gallery_id = (System.Int32)gallery.id;
}

return _gallery_id;
}
set 
{
if ( _gallery_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_gallery = null;

_gallery_id = value ;
OnPropertyChanged("gallery_id");
}
}
}

/// <summary>
/// Collection of art_rate_type.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "91dd5bf9-ce4c-4fd6-bedb-c220b9b80686" , CollectionOfType = typeof(art_rate_type)) ]
public virtual IList<art_rate_type> art_rate_types 
{
get
{
 if (_art_rate_types == null) _art_rate_types = new List<art_rate_type>();

return _art_rate_types;
}
set 
{
if ( _art_rate_types != value) 
{
_art_rate_types = value ;
}
}
}

/// <summary>
/// Collection of art_tag.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "4c42501e-7a88-478e-b1ba-f39351653d47" , CollectionOfType = typeof(art_tag)) ]
public virtual IList<art_tag> art_tags 
{
get
{
 if (_art_tags == null) _art_tags = new List<art_tag>();

return _art_tags;
}
set 
{
if ( _art_tags != value) 
{
_art_tags = value ;
}
}
}

/// <summary>
/// Collection of comment.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "baf04a50-8a61-43e2-85d9-b710c6c3e5c4" , CollectionOfType = typeof(comment)) ]
public virtual IList<comment> comments 
{
get
{
 if (_comments == null) _comments = new List<comment>();

return _comments;
}
set 
{
if ( _comments != value) 
{
_comments = value ;
}
}
}

/// <summary>
/// Collection of lastWeekVisit.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "c26638fb-b2e2-4108-a85c-ada5340b01bf" , CollectionOfType = typeof(lastWeekVisit)) ]
public virtual IList<lastWeekVisit> lastWeekVisits 
{
get
{
 if (_lastWeekVisits == null) _lastWeekVisits = new List<lastWeekVisit>();

return _lastWeekVisits;
}
set 
{
if ( _lastWeekVisits != value) 
{
_lastWeekVisits = value ;
}
}
}

/// <summary>
/// Collection of topRated.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "a9eb7773-101b-4e29-8d44-bc4effacb27b" , CollectionOfType = typeof(topRated)) ]
public virtual IList<topRated> topRateds 
{
get
{
 if (_topRateds == null) _topRateds = new List<topRated>();

return _topRateds;
}
set 
{
if ( _topRateds != value) 
{
_topRateds = value ;
}
}
}

/// <summary>
/// Collection of visit.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "b3c75d20-823d-4333-a89d-ace6390fbd49" , CollectionOfType = typeof(visit)) ]
public virtual IList<visit> visits 
{
get
{
 if (_visits == null) _visits = new List<visit>();

return _visits;
}
set 
{
if ( _visits != value) 
{
_visits = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Art_Art_type1
/// </summary>
[GenWiseAttribute(RelationID = "4d986693-4178-4e49-b16d-f130d50304b2") ]
public virtual art_type art_type 
{
get
{
if ( _art_type == null ) 
{
if (  _art_type_id.Equals(0)  || _art_type_id.Equals(System.Int32.MinValue) ) 
{
if ( _art_type != null && ( _art_type.id.Equals(System.Int32.MinValue) ) )
{
  _art_type = null;
}
}
else
{
_art_type = (new art_typeFactory()).Get(_art_type_id);
}
}

return _art_type;
}
set 
{
if ( _art_type != value) 
{
if ( value==null ) _art_type_id = System.Int32.MinValue; else _art_type_id = (System.Int32)value.id; 
_art_type = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Art_Gallery
/// </summary>
[GenWiseAttribute(RelationID = "57089956-1b3f-4ef2-9814-fce17bcd524b") ]
public virtual gallery gallery 
{
get
{
if ( _gallery == null ) 
{
if ( !_gallery_id.HasValue || _gallery_id.Value.Equals(System.Int32.MinValue) ) 
{
if ( _gallery != null && ( _gallery.id.Equals(null) ) )
{
  _gallery = null;
}
}
else
{
_gallery = (new galleryFactory()).Get(_gallery_id.Value);
}
}

return _gallery;
}
set 
{
if ( _gallery != value) 
{
if ( value==null ) _gallery_id = null; else _gallery_id = (System.Int32)value.id; 
_gallery = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Art_User1
/// </summary>
[GenWiseAttribute(RelationID = "da291ced-902c-41ba-ac86-9c9ef3b2108a") ]
public virtual user user 
{
get
{
if ( _user == null ) 
{
if (  _user_id.Equals(0)  || _user_id.Equals(System.Int32.MinValue) ) 
{
if ( _user != null && ( _user.id.Equals(System.Int32.MinValue) ) )
{
  _user = null;
}
}
else
{
_user = (new userFactory()).Get(_user_id);
}
}

return _user;
}
set 
{
if ( _user != value) 
{
if ( value==null ) _user_id = System.Int32.MinValue; else _user_id = (System.Int32)value.id; 
_user = value ;
}
}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new art object. 
/// </summary>
public  art()
{
_id = System.Int32.MinValue;

}

/// <summary>
/// Add a new art_rate_type object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="part_rate_type">An art_rate_type object to be added to this objects collection.</param>
public virtual void Addart_rate_type(art_rate_type part_rate_type)
{
if( part_rate_type == null  ) throw new ArgumentNullException("part_rate_type");
// Set the Parent Property
part_rate_type.art = this;
if (!part_rate_type.IsValid) { throw new Exception("part_rate_type failed on the Validate() method." + Error.ErrorsToString( part_rate_type.Validate() ) ); }
art_rate_types.Add(part_rate_type);
}

/// <summary>
/// Delete an existing art_rate_type object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="part_rate_type">The art_rate_type object to be removed from this objects collection.</param>
public virtual void Deleteart_rate_types(art_rate_type part_rate_type)
{
if( part_rate_type == null  ) throw new ArgumentNullException("part_rate_type");
art_rate_types.Remove(part_rate_type);
// Remove the Association with the Parent object
part_rate_type.art = null;
}

/// <summary>
/// Add a new comment object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pcomment">An comment object to be added to this objects collection.</param>
public virtual void Addcomment(comment pcomment)
{
if( pcomment == null  ) throw new ArgumentNullException("pcomment");
// Set the Parent Property
pcomment.art = this;
if (!pcomment.IsValid) { throw new Exception("pcomment failed on the Validate() method." + Error.ErrorsToString( pcomment.Validate() ) ); }
comments.Add(pcomment);
}

/// <summary>
/// Delete an existing comment object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pcomment">The comment object to be removed from this objects collection.</param>
public virtual void Deletecomments(comment pcomment)
{
if( pcomment == null  ) throw new ArgumentNullException("pcomment");
comments.Remove(pcomment);
// Remove the Association with the Parent object
pcomment.art = null;
}

/// <summary>
/// Add a new lastWeekVisit object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="plastWeekVisit">An lastWeekVisit object to be added to this objects collection.</param>
public virtual void AddlastWeekVisit(lastWeekVisit plastWeekVisit)
{
if( plastWeekVisit == null  ) throw new ArgumentNullException("plastWeekVisit");
// Set the Parent Property
plastWeekVisit.art = this;
if (!plastWeekVisit.IsValid) { throw new Exception("plastWeekVisit failed on the Validate() method." + Error.ErrorsToString( plastWeekVisit.Validate() ) ); }
lastWeekVisits.Add(plastWeekVisit);
}

/// <summary>
/// Delete an existing lastWeekVisit object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="plastWeekVisit">The lastWeekVisit object to be removed from this objects collection.</param>
public virtual void DeletelastWeekVisits(lastWeekVisit plastWeekVisit)
{
if( plastWeekVisit == null  ) throw new ArgumentNullException("plastWeekVisit");
lastWeekVisits.Remove(plastWeekVisit);
// Remove the Association with the Parent object
plastWeekVisit.art = null;
}

/// <summary>
/// Add a new topRated object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="ptopRated">An topRated object to be added to this objects collection.</param>
public virtual void AddtopRated(topRated ptopRated)
{
if( ptopRated == null  ) throw new ArgumentNullException("ptopRated");
// Set the Parent Property
ptopRated.art = this;
if (!ptopRated.IsValid) { throw new Exception("ptopRated failed on the Validate() method." + Error.ErrorsToString( ptopRated.Validate() ) ); }
topRateds.Add(ptopRated);
}

/// <summary>
/// Delete an existing topRated object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="ptopRated">The topRated object to be removed from this objects collection.</param>
public virtual void DeletetopRateds(topRated ptopRated)
{
if( ptopRated == null  ) throw new ArgumentNullException("ptopRated");
topRateds.Remove(ptopRated);
// Remove the Association with the Parent object
ptopRated.art = null;
}

/// <summary>
/// Add a new visit object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pvisit">An visit object to be added to this objects collection.</param>
public virtual void Addvisit(visit pvisit)
{
if( pvisit == null  ) throw new ArgumentNullException("pvisit");
// Set the Parent Property
pvisit.art = this;
if (!pvisit.IsValid) { throw new Exception("pvisit failed on the Validate() method." + Error.ErrorsToString( pvisit.Validate() ) ); }
visits.Add(pvisit);
}

/// <summary>
/// Delete an existing visit object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pvisit">The visit object to be removed from this objects collection.</param>
public virtual void Deletevisits(visit pvisit)
{
if( pvisit == null  ) throw new ArgumentNullException("pvisit");
visits.Remove(pvisit);
// Remove the Association with the Parent object
pvisit.art = null;
}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();
return _errors;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

